#!/bin/bash
VER=`sed -n '/version\ =/p' ./cfg.py | awk '{print $3}'`

VER=${VER#\"}
VER=${VER%\"}

FIRST=`echo $VER | awk 'BEGIN { FS="." }{print $1}'`
SECOND=`echo $VER | awk 'BEGIN { FS="." }{print $2}'`

NEW_VER=$[ $SECOND + 1 ]

Green=$'\e[1;32m'
Normal=$'\e[0m'

echo
echo "update to: $Green$FIRST.$NEW_VER$Normal"
echo "  old ver: $FIRST.$SECOND"

sed -i "s/$FIRST.$SECOND/$FIRST.$NEW_VER/" ./cfg.py

rm -rf ./output

TDIR=mes_$FIRST.$NEW_VER

mkdir -p ./output/$TDIR

python ./nd.py

cd output/$TDIR
    
echo
echo -e "...................................copy mestool"
cp -r ~/mes/deploy/cmd/gen/mestool .

cd ..

FILENAME=mes_$FIRST.$NEW_VER.tar.gz

tar cjf $FILENAME ./$TDIR

echo
echo "the update file is: $Green$FILENAME$Normal"
echo
